<template>
	<h3>get instance</h3>
    <p>{{xy}}</p>
</template>

<script>
	import { onMounted, getCurrentInstance } from "vue";

	export default {
		name: "GetInstance",
		data() {
			return {
				x: 1,
				y: 2,
			};
		},

		setup(props,context) {
			console.log("setup this=", this);
			const instance = getCurrentInstance();
			console.log("instance", instance);

			onMounted(() => {
				console.log("this in onMounted", this);
				console.log("x", instance.data.x);
			});
		},

		/* 在vue2的系列API中可以获取this */
		mounted() {
			console.log("mounted this=", this);
			console.log("y", this.y);
		},

		computed: {
			xy() {
				console.log("computed this=",this);
				return this.x + this.y;
			},
		},
	};
</script>